﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace bxml.betterxml.xelement
{
    //public class RunType<T> where T : XElement
    //{
    //}

public class XNameSpace {
	private Dictionary<String, Type > elementToClassMappings = new Dictionary<String, Type>();
	private readonly String uri;
	
	/* defaultClass is private because I have made the decision that you should not be able
	 * to change the default class while it is running, it is default for a reason -- we can 
	 * change this later if need be.
	 */
	private readonly Type defaultClass;
	

	public XNameSpace(String uri) 
        :this(typeof(XElement), uri)
    {
    
	}
	
	public XNameSpace(Type defaultClass, String uri)
    {
		this.defaultClass = defaultClass;
		this.uri = uri;
	}
	
	public String getURI() {
		return uri;
	}
		
	public void setElementMapping(String elementName,  Type klass) //throws BetterXmlException 
    {
		elementToClassMappings.Add(elementName, klass);
	}
	
	public Dictionary <String, Type> getMappings<T>() //where T is XElement
    {
		return elementToClassMappings;
	}
	
	public Type getClass(String elementName) 
    {
		Type klass = elementToClassMappings[elementName];
		if (klass == null) {
			return defaultClass;
		}
		return klass;
	}
	
	public Type getDefaultClass() {
		return defaultClass;
	}
	
}

}
